package com.water.dmdb.util;

import com.water.dmdb.db.DmConnPool;
import com.water.dmdb.db.MySQLConnPool;
import com.water.dmdb.db.OracleConnPool;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcUtil {
    //达梦数据库连接池
    private static DmConnPool dmConnPool = new DmConnPool();
    //oracle数据库连接池
    private static OracleConnPool oracleConnPool = new OracleConnPool();
    //mysql数据库连接池
    private static MySQLConnPool mysqlConnPool = new MySQLConnPool();

    /**
     * 从池中获取一个连接
     *
     * @return
     * @throws SQLException
     */
    public static Connection getDmConnection() throws SQLException {
        return dmConnPool.getConnection();

    }

    /**
     * 从池中获取一个连接
     *
     * @return
     * @throws SQLException
     */
    public static Connection getOracleConnection() throws SQLException {
        return oracleConnPool.getConnection();
    }

    /**
     * 关闭连接
     *
     * @param conn
     * @param st
     * @param rs
     * @throws SQLException
     */
    public static void CloseConnection(Connection conn, Statement st, ResultSet rs) throws SQLException {
        // 关闭存储查询结果的ResultSet对象
        if (rs != null) {
            rs.close();
        }
        //关闭Statement对象
        if (st != null) {
            st.close();
        }
        //关闭连接
        if (conn != null) {
            conn.close();
        }
    }

    public static Connection getMYSQLConnection() throws SQLException {
        return mysqlConnPool.getConnection();
    }
}
